package com.wuhan.template.module.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseApplication;
import com.wuhan.template.base.BaseViewHolder;
import com.wuhan.template.base.MyBaseAdapter;
import com.wuhan.template.module.home.entity.HotWordEntity;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/5/13 0013.
 */
public class HotSearchBaseAdapter extends MyBaseAdapter<HotWordEntity>{
    private Context context;
    private ImageLoader loader;
    private DisplayImageOptions options;
    public HotSearchBaseAdapter(Context context, List list) {
        super(context, list);
        this.context = context;
        loader = ((BaseApplication) (context.getApplicationContext())).getImageLoader();
        options = new DisplayImageOptions.Builder()
                .cacheOnDisk(true)
                .cacheOnDisk(true)
                .showImageOnFail(R.mipmap.app_logo)
                .build();
    }

    @Override
    public int getLayoutId() {
        return R.layout.hotsearch_list_item;
    }

    @Override
    public BaseViewHolder getViewHolder() {

        return new ViewHolder();
    }

    @Override
    public void bindViews(View view, BaseViewHolder viewHolder) {
        ViewHolder holder = (ViewHolder) viewHolder;
        final HotWordEntity item = getItem(holder.position);
        String replace = item.getTitle().replace("<em>", "");
        holder.title.setText(replace.replace("</em>", ""));
        holder.classify.setText(item.getColumn_name());
        String url =item.getIndexpic().getHost()+ item.getIndexpic().getDir()+ item.getIndexpic().getFilepath()
                + item.getIndexpic().getFilename();
        loader.displayImage(url,holder.image,options);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context,"点击查看",Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(context,SearchDetailActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("searchId",item.getId());
                context.startActivity(intent);
            }
        });

    }
    public static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.hot_title)
        TextView title;
        @BindView(R.id.hot_itemImage)
        ImageView image;
        @BindView(R.id.hot_classify)
        TextView classify;

    }
}
